<?php


namespace App\Models\CacheModel;


use app\common\lib\exception\ApiException;
use App\Models\Api\BaseCache;
use AstroTool\Cache\CacheManage;

class ThirdApp extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl_third_app';

    protected $cacheModel = 'third.app';

    /**
     * 缓存获取三方app信息
     * @param $id
     * @return array|bool|mixed
     * @throws \Exception
     */
    public function getThirdInfoFromCache($id)
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $id)->getDataAndSet(function () use ($id)
        {
            return $this->getThirdInfoFromDb($id);
        }, ['id', 'create_time', 'android_package_name', 'ios_package_name', 'command_text', 'third_href', 'des']);
        return $data;
    }

    /**
     * 数据库获取获取三方app信息
     * @param $id
     * @return array
     */
    public function getThirdInfoFromDb($id)
    {
        try
        {
            $data = $this
                ->where(['id' => $id, 'status' => 1])
                ->findOrFail()->toArray();
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        return $data;
    }
}
